﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
namespace ERP.Classes
{
    public class cs_erp_chitiet_khoInfo
    {
        private int _id_chitiet;
        private int _malannhap;
        private int _mahh;
        private int _makho;
        private double _soluong;
        private double _dongia;
        private double _daxuat;
        private double _conlai;
        private int _trangthai;

        public cs_erp_chitiet_khoInfo(int id_chitiet, int malannhap, int mahh, int makho, double soluong, double dongia, double daxuat, double conlai, int trangthai)
        {
            this._id_chitiet = id_chitiet;
            this._malannhap = malannhap;
            this._mahh = mahh;
            this._makho = makho;
            this._soluong = soluong;
            this._dongia = dongia;
            this._daxuat = daxuat;
            this._conlai = conlai;
            this._trangthai = trangthai;

        }
        public cs_erp_chitiet_khoInfo()
        {
            this._id_chitiet = 0;
            this._malannhap = 0;
            this._mahh = 0;
            this._makho = 0;
            this._soluong = 0;
            this._dongia = 0;
            this._daxuat = 0;
            this._conlai = 0;
            this._trangthai = 0;

        }
        public int id_chitiet
        {
            get
            {
                return this._id_chitiet;
            }
            set
            {
                this._id_chitiet = value;
            }
        }
        public int malannhap
        {
            get
            {
                return this._malannhap;
            }
            set
            {
                this._malannhap = value;
            }
        }
        public int mahh
        {
            get
            {
                return this._mahh;
            }
            set
            {
                this._mahh = value;
            }
        }
        public int makho
        {
            get
            {
                return this._makho;
            }
            set
            {
                this._makho = value;
            }
        }
        public double soluong
        {
            get
            {
                return this._soluong;
            }
            set
            {
                this._soluong = value;
            }
        }
        public double dongia
        {
            get
            {
                return this._dongia;
            }
            set
            {
                this._dongia = value;
            }
        }
        public double daxuat
        {
            get
            {
                return this._daxuat;
            }
            set
            {
                this._daxuat = value;
            }
        }
        public double conlai
        {
            get
            {
                return this._conlai;
            }
            set
            {
                this._conlai = value;
            }
        }
        public int trangthai
        {
            get
            {
                return this._trangthai;
            }
            set
            {
                this._trangthai = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[10];
            paraName[0] = "@id_chitiet";
            paraName[1] = "@malannhap";
            paraName[2] = "@mahh";
            paraName[3] = "@makho";
            paraName[4] = "@soluong";
            paraName[5] = "@dongia";
            paraName[6] = "@daxuat";
            paraName[7] = "@conlai";
            paraName[8] = "@trangthai";
            paraName[9] = "@option";
            object[] paraValue = new object[10];
            paraValue[0] = this._id_chitiet;
            paraValue[1] = this._malannhap;
            paraValue[2] = this._mahh;
            paraValue[3] = this._makho;
            paraValue[4] = this._soluong;
            paraValue[5] = this._dongia;
            paraValue[6] = this._daxuat;
            paraValue[7] = this._conlai;
            paraValue[8] = this._trangthai;
            paraValue[9] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 10, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_CHITIET_KHO", option);
        }

        
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_CHITIET_KHO", "id_chitiet = " + this._id_chitiet);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_chitiet = Convert.ToInt32(ds.Tables[0].Rows[0]["id_chitiet"].ToString().Trim());
                this._malannhap = Convert.ToInt32(ds.Tables[0].Rows[0]["malannhap"].ToString().Trim());
                this._mahh = Convert.ToInt32(ds.Tables[0].Rows[0]["mahh"].ToString().Trim());
                this._makho = Convert.ToInt32(ds.Tables[0].Rows[0]["makho"].ToString().Trim());
                this._soluong = Convert.ToDouble(ds.Tables[0].Rows[0]["soluong"].ToString().Trim());
                this._dongia = Convert.ToDouble(ds.Tables[0].Rows[0]["dongia"].ToString().Trim());
                this._daxuat = Convert.ToDouble(ds.Tables[0].Rows[0]["daxuat"].ToString().Trim());
                this._conlai = Convert.ToDouble(ds.Tables[0].Rows[0]["conlai"].ToString().Trim());
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }
    }
}
